{extend name="$BASE_LIST" /}
{block name="body"}
<div class="right-main">
    <div class="page_nav" id="js_page_nav"><span class="page_title">{$page_nav}</span></div>
    <div id="js_main_header" class="ui-form main_header">
        <span class="frm_input_box search append">
            <a href="javascript:void(0);" id="js_search" class="frm_input_append">
                <i class="icon wb-search" title="搜索"></i>
            </a>
            <input type="text" id="js_keyword" placeholder="请输入用户名" value="" class="frm_input" />
        </span>
        <span class="right">       
        </span>
    </div>
    <table id="grid-table">
        <thead frozen="true">
        <th data-options="field:'user_id',width:100,align:'center'">用户id</th>
        <th data-options="field:'username',width:100,align:'center'">用户名</th>
        <th data-options="field:'ref_no',width:100,align:'center'">订单号</th>
        <th data-options="field:'amount',width:100,align:'center',">金额</th>
        <th data-options="field:'status',width:100,align:'center',formatter:formatType">是否发布</th>
        </thead>
        <thead>
            <tr>
                <th data-options="field:'add_time',width:150, align:'center'">创建时间</th>
                <th data-options="field:'update_time',width:150, align:'center'">更新时间</th>
                <th data-options="field:'_oper',halign:'center',formatter: formatOper">操作</th>
            </tr>
        </thead>
    </table>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    function formatOper(value, row, index) {
        var html = '<span class="grid-operation">';
        // html += '<button type="button" onclick="edit(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>编辑</button>';
        html += '<button type="button" onclick="del(' + row['id'] + ')" class="btn btn-xs btn-default edit-btn"><i class="icon wb-edit"></i>删除</button>';
        html += '</span>';
        return html;
    }
    function formatImg(value, row, index) {
        html = '';
        if(value!=null){
            html = '<a href="'+value+'" target="_blank"><img src="'+value+'" style="max-width:50px;max-height:20px;text-align: center"></a>';
        }
        return html;
    }

    function formatVideo(value, row, index) {
        html = '';
        if(value!=null){
            html = '<video src="'+value+'" style="max-width:50px;max-height:20px;text-align: center" onclick="openVideo(\''+value+'\')"></video>';
        }
        return html;
    }

    function openVideo(path){
        var url = getURL('play')+'?path='+path;
        openBarWin('播放视频', 1000, 600, url, function () {
            reload();
        });
    }
    
    $(function () {
        $('#grid-table').datagrid({
            url: getURL('loadList'),
            method: "GET",
            height: getGridHeight(),
            rownumbers: true,
            singleSelect: true,
            remoteSort: false,
            multiSort: true,
            emptyMsg: '<span>无相关数据</span>',
            pagination: true,
            pageSize: 20
        });
        //设置分页控件 
        $('#grid-table').datagrid('getPager').pagination({
            pageSize: 20, //每页显示的记录条数，默认为10 
            pageList: [20, 30, 50]
        });
    });
    
    $("#js_addBtn").click(function () {
        var url = getURL('edit');
        openBarWin('添加视频', 1000, 600, url, function () {
            reload();
        });
    });
    function formatAuth(value,row,index){
        var text = '<span style="color:red">未审核</span>';
        if(value == 1){
            text = '<span style="color:green">已审核</span>';
        }else if(value == 2){
            text = '<span style="color:#ff9b00">不通过</span>';
        }
        return text;
    }
    function formatType(value,row,index){
        var text = '<span style="color:green">未支付</span>';
        if(value == 10){
            text = '<span style="color:red">已支付</span>';
        }
        return text;
    }
    function formatOnline(value,row,index){
        var text = '<span style="color:green">在线</span>';
        if(value == 1){
            text = '<span style="color:red">离线</span>';
        }
        return text;
    }
    function edit(id) {
        var url = getURL('edit', 'id=' + id);
        openBarWin('编辑', 800, 600, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function del(id) {
        confirm("确认要删除此视频吗？", function () {
            var url = getURL('del');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }
    
    function appr(id) {
        confirm("确认通过审核？", function () {
            var url = getURL('changeStatus');
            $.getJSON(url, {id: id}, function (json) {
                if (json.success)
                    reload();
                else
                    alert(json.message);
            });
        });
    }

    function show_certificate(id) {
        var url = getURL('show_certificate', 'id=' + id);
        openBarWin('笔者资料', 1000, 800, url, function () {
            reload();
        }, ['确定','取消']);
    }

    function cancel_appr(id) {
        var url = getURL('cancel_appr','id='+id);
        openBarWin('确认要拒绝此笔者通过审核吗?', 600, 300, url, function () {
            reload();
        }, ['确定','取消']);
    }

    $("#js_search").click(function () {
        reload();
    });
    
    $("#check_state").change(function(){
        reload();
    })
    $("#type").change(function(){
        reload();
    })
    function reload() {
        var keyword = $("#js_keyword").val();
        var check_state  = $("#check_state").val();
        var type = $("#type").val();
        $('#grid-table').datagrid('reload', {
            keyword: keyword,
            check_state: check_state,
            type: type,
        });
    }

</script>
{/block}